package com.ruoyi.fly.service.impl;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.fly.domain.ProductCategory;
import com.ruoyi.fly.domain.vo.ProductCategoryVo;
import com.ruoyi.fly.mapper.ProductCategoryMapper;
import com.ruoyi.fly.service.ProductCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ProductCategoryServiceImpl implements ProductCategoryService  {

    @Autowired
    private ProductCategoryMapper productCategoryMapper;

    /**
     * 根据id查询产品分类
     * @param id 产品分类主键
     * @return
     */
    @Override
    public ProductCategory selectProductCategoryById(String id) {
        ProductCategory productCategory = productCategoryMapper.selectProductCategoryById(id);
       return productCategory;
    }

    /**
     * 查询产品分类列表
     * @return
     */
    @Override
    public List<ProductCategory> selectProductCategoryList(ProductCategory productCategory) {
        return productCategoryMapper.selectProductCategoryList(productCategory);
    }

    /**
     * 新增产品分类
     * @param productCategoryVo 产品分类
     * @return
     */
    @Override
    public R insertProductCategory(ProductCategoryVo productCategoryVo) {
        productCategoryVo.setCreateTime(DateUtils.getNowDate());
        productCategoryVo.setCreateBy(String.valueOf(SecurityUtils.getUserId()));
        return productCategoryMapper.insertProductCategory(productCategoryVo)>0?R.ok("新增成功"):R.fail("操作失败");
    }

    /**
     * 修改产品分类
     * @param productCategoryVo 产品分类
     * @return
     */
    @Override
    public R updateProductCategory(ProductCategoryVo productCategoryVo) {
        productCategoryVo.setUpdateTime(DateUtils.getNowDate());
        productCategoryVo.setUpdateBy(String.valueOf(SecurityUtils.getUserId()));
        return productCategoryMapper.updateProductCategory(productCategoryVo)>0?R.ok("修改成功"):R.fail("操作失败");
    }

    /**
     * 删除产品分类信息
     * @param id 产品分类主键
     * @return
     */
    @Override
    public R deleteProductCategoryById(String id) {
        return productCategoryMapper.deleteProductCategoryById(id)>0?R.ok("删除成功"):R.fail("操作失败");
    }

    @Override
    public R deleteProductCategoryByIds(String[] id) {
        return productCategoryMapper.deleteProductCategoryByIds(id)>0?R.ok("删除成功"):R.fail("操作失败");
    }
}
